from typing import Union

from api.internal.status import Status


def success(data=None):
    if data is None:
        data = {}
    return {
        "code": Status.SUCCESS,
        "msg": Status.StatusDic[Status.SUCCESS],
        "data": data,
    }


def failure(data=None):
    if data is None:
        data = {}
    return {
        "code": Status.FAILURE,
        "msg": Status.StatusDic[Status.FAILURE],
        "data": data,
    }


def params_error(data=None):
    if data is None:
        data = {}
    return {
        "code": Status.INVALID_PARAMETER,
        "msg": Status.StatusDic[Status.INVALID_PARAMETER],
        "data": data,
    }


def error(data=None):
    if data is None:
        data = {}
    return {
        "code": Status.UNKNOWN,
        "msg": Status.StatusDic[Status.UNKNOWN],
        "data": data,
    }


def to_json(code: int, msg: str = None, data: any = []):
    if msg is None:
        msg = Status.StatusDic[code]
    return {"code": code, "msg": msg, "data": data}
